
<?php 
if(isset($_GET["id"]) && isset($_GET["page"]) )
{	
	$page = $_GET["page"];
	$idBill = $_GET["id"];
	include_once("../../DataProvider.php");
	
	$sql = "select * from tbl_bills where IDBill = $idBill";
	$result = DataProvider::ExecuteQuery($sql);
	if($row = mysql_fetch_array($result))
	{
		
		$listGame = "";
		$sql1 = "select IDGame from tbl_detailbill where IDBill = $idBill";
		$result1 = DataProvider::ExecuteQuery($sql1);
		while($row1 = mysql_fetch_array($result1))
		{
			$listGame = $listGame. "," .$row1["IDGame"];
		}
		$listGame = substr($listGame,1);
		$time = strtotime($row["CreateDate"]);
		$date = date("d-m-Y",$time);
		?>
		<div>Họ tên/Email: <?php echo $row["UserName"] ?> </div>
	
		<div>Ngày đặt: <?php   echo $date; ?> </div>
		<table cellpadding="0" cellspacing="0" style="border-left:1px solid #E1E1E1;" width="700px">
		<tr >
			<th align="center" style="background-color:#C0DCC0;border-left:1px solid #E1E1E1;" >STT</th>
			<th align="center" style="background-color:#C0DCC0;border-left:1px solid #E1E1E1;" >Mã số</th>
			<th align="center" style="background-color:#C0DCC0;border-left:1px solid #E1E1E1;" >Hình</th>
			<th align="left" style="background-color:#C0DCC0;border-left:1px solid #E1E1E1;" >Tên game</th>
			<th align="right"style="background-color:#C0DCC0;border-left:1px solid #E1E1E1;" >Giá</th>
		</tr>
		<?php
	$sql2 ="SELECT * FROM tbl_games WHERE GameID IN (".$listGame." )";
	$result2 = DataProvider::ExecuteQuery($sql2);
	$tongsorecord = 0;
	if($result2)
	{
		$tongsorecord = mysql_num_rows($result2);
	}
	$y = 9;
	$tongsotrang = ceil($tongsorecord/$y);
	if($page > $tongsotrang)
	{
		$page = $tongsotrang;
	}
	$start = ($page-1)*$y;
	
	$totalPrice = 0;
	if($tongsorecord == 0){
		//echo "Không có tin nào";	
	}
	else
	{
		while($row2 = mysql_fetch_array($result2))
		{
			$totalPrice+=$row2["Price"];
		}

		$sql3 ="SELECT * FROM tbl_games WHERE GameID IN (".$listGame." ) order by GameName limit $start,$y";
		$result3 = DataProvider::ExecuteQuery($sql3);
		$stt = $start;
		while($row3 = mysql_fetch_array($result3))
		{
			$stt++;
			?>
			<tr>
			<td align="center" width="40px"> <?php echo $stt ?></td>
			<td align="center" width="70px"> <?php echo $row3["GameID"] ?></td>
			<td  width="75px"><div style="background: url(<?php echo $row3["Artwork"] ?>) no-repeat; background-size:70px; float:left; "><img src="../img/mask175_t.png" height="70px" width="70px" /></div></td>
			<td align="left" nowrap="wrap"><?php echo $row3["GameName"] ?></td>
			<td align="right"><?php echo number_format($row3["Price"], 0, '.', ',')?> VNĐ</td>
		   
		</tr>
<?php	}
	}
	
?>
<tr>
    <td colspan="4" align="right"> Tổng tiền:&nbsp;&nbsp;
    </td>
    <td align="right">
    <?php echo number_format($totalPrice,0,".",",") ;?> VNĐ
    </td>
</tr>
<tr>
<td align="right" colspan="5" bgcolor="#CCCCCC"><div class="pagenav"><table cellpadding="3" cellspacing="1" border="0" style="background: none repeat scroll 0 0 #FFFFFF;
    border: 1px solid #B0BDC6;
    color: #000000; margin-right:5px;"><tr><td class="vbmenu_control">Trang <?php echo $page."/".$tongsotrang; ?>&nbsp;</td>
        <?php
        if($page == 1)
				{echo"<td class='alt2'><< Đầu </td>";}
				else
				{
				echo"<td class='alt1'><a style='text-decoration:none;' href='#1' onclick='javascript:loadBillAddmin(1,".$idBill.");'><< Đầu </a> </td>";}
				if($page-3>0)
				$i = $page-3;
				else
				$i = 1;
			for($i;$i<=$tongsotrang;$i++)
			{
				if($tongsotrang < 5)
				{
					if($i == $page)
					{
					 echo "<td class='alt2'>$i</td>";	
					}
					else
					{
						echo "<td class='alt1'><a style='text-decoration:none;' href='#$i' onclick='javascript:loadBillAddmin($i,".$idBill.");'> $i</a>  </td>";	
					}
				}
				else
				{
					if($i<$page+4)
					{
						if($i == $page)
						{
						 echo "<td class='alt2'>$i</td>";	
						}
						else
						{
							echo "<td class='alt1'><a style='text-decoration:none;' href='#$i' onclick='javascript:loadBillAddmin($i,".$idBill.");'> $i</a>  </td>";	
						}
					}
					else
					{
						echo "<td class='alt1'>...</td>";	
						if( $i * 5 <= $tongsotrang)
						{
							if($i * 5 == $page)
							{
								 echo "<td class='alt2'> $i * 5 </td>";
							}
							else
							 echo "<td class='alt1'><a style='text-decoration:none;' href='#$i * 5' onclick='javascript:loadBillAddmin($i*5,".$idBill.");'> $i * 5</a>  </td>";
							
							  break;
						}
						else
						{
							if($tongsotrang == $page)
							{
								 echo "<td class='alt2'> $tongsotrang </td>";
							}
							else
							 echo "<td class='alt1'><a style='text-decoration:none;' href='#$tongsotrang' onclick='javascript:loadBillAddmin($tongsotrang,".$idBill.");'> $tongsotrang</a>  </td>";
							
							  break;
							
						}
					}
				}
			}
			if($page == $tongsotrang)
				{echo"<td class='alt2'> Cuối >></td>";}
				else
				{
				echo"<td class='alt1' ><a style='text-decoration:none;' href='#$tongsotrang' onclick='javascript:loadBillAddmin($i,".$idBill.");'> Cuối >> </a></td>";
				}
}?><td style="cursor: pointer;" id="pagenav.37" class="vbmenu_control" title="" > <img border="0" alt="" title="" src="../images/menu_open.gif" onclick="showgopage()"><div class="vbmenu_popup" id="pagenav_menu" style="position: absolute; z-index: 999999; clip: rect(auto, auto, auto, auto); display: none;">
		<table cellspacing="1" cellpadding="4" border="0">
		<tbody><tr>
			<td nowrap="nowrap" class="thead" style="background-color:#5C7099;">Go to Page...</td>
		</tr>
		<tr>
			<td class="vbmenu_option" title="">
			<form action="javascript:loadBillAddmin(document.gopage.go.value,<?php echo $idBill; ?>)" method="get" onsubmit="return checkgo();" id="pagenav_form" name="gopage">
				<input type="text" class="bginput" id="pagenav_itxt" name="go" style="font-size:11px" size="4">
				<input type="submit" class="button1" id="pagenav_ibtn" value="Go">
			</form>
			</td>
		</tr>
		</tbody></table>
	</div></td>
</tr></table></div></td></tr>

</table><?php } ?>